import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {LocalStorageService} from './local-storage.service';

@Component({selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})
export class AppComponent implements OnInit {
  title = 'app';
  urlPath : string = "";
  cid : number = 0;
  private lStorage : LocalStorageService = new LocalStorageService();

  constructor(private route : Router) {
    //this.lStorage.clearAll();
  }

  ngOnInit() {
    this
      .route
      .events
      .subscribe((ev) => {
        if (ev["url"]) {
          let segs = ev["url"]
            .split("/")
            .filter(x => x.trim())
          this.urlPath = segs[0];
          if (this.urlPath) {
            let qc = this
              .urlPath
              .indexOf("?");
            if (qc != -1) {
              this.urlPath = this
                .urlPath
                .substr(0, qc);
            }
          }
          if (this.urlPath == "category") {
            this.cid = parseInt(segs[segs.length - 1]);
          }
        }
      });
  }
}
